//
//  MPOtherHomeHeaderView.m
//  MPOtherHomeDemo
//
//  Created by YC on 2018/9/5.
//  Copyright © 2018年 yc. All rights reserved.
//

#import "MPOtherHomeHeaderView.h"
#import <Masonry/Masonry.h>

@interface MPOtherHomeHeaderView ()

/// 背景
@property (nonatomic, strong) UIImageView *bgImageView;

/// 头像
@property (nonatomic, strong) UIImageView *headImageView;

/// 昵称
@property (nonatomic, strong) UILabel *nickLabel;

/// 年龄标签，如“90后”
@property (nonatomic, strong) UILabel *ageTagLabel;

/// 性别  男/女
@property (nonatomic, strong) UILabel *sexLabel;

/// 聊天按钮
@property (nonatomic, strong) UIButton *chatBtn;

/// 喜欢按钮
@property (nonatomic, strong) UIButton *likeBtn;

@end

@implementation MPOtherHomeHeaderView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if(self) {
        [self createUI];
    }
    return self;
}

#pragma mark - 添加视图
- (void)createUI {
    [self addSubview:self.bgImageView];
    [self.bgImageView addSubview:self.headImageView];
    [self.bgImageView addSubview:self.nickLabel];
    [self.bgImageView addSubview:self.ageTagLabel];
    [self.bgImageView addSubview:self.sexLabel];
    
    // test
    self.nickLabel.text = @"myNick";
    self.ageTagLabel.text = @"90后";
    self.sexLabel.text = @"女";
    
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.equalTo(@0);
    }];
    
    [self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bgImageView.mas_left).offset(10);
        make.size.mas_equalTo(CGSizeMake(44, 44));
        make.centerY.equalTo(self.mas_centerY).offset(10);
    }];
    
    [self.nickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headImageView.mas_right).offset(10);
        make.centerY.equalTo(self.headImageView.mas_centerY).offset(-7);
    }];
    
    [self.ageTagLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nickLabel.mas_left);
        make.centerY.equalTo(self.headImageView.mas_centerY).offset(7);
    }];
    
    [self.sexLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.ageTagLabel.mas_right).offset(10);
        make.centerY.equalTo(self.ageTagLabel.mas_centerY);
    }];
    
    [self.chatBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
    }];
}

#pragma mark - Getters/Setters
- (UIImageView *)bgImageView {
    if(!_bgImageView) {
        _bgImageView = [UIImageView new];
    }
    return _bgImageView;
}

- (UIImageView *)headImageView {
    if(!_headImageView) {
        _headImageView = [UIImageView new];
        _headImageView.layer.cornerRadius = 22;
        _headImageView.backgroundColor = [UIColor whiteColor];
    }
    return _headImageView;
}

- (UILabel *)nickLabel {
    if(!_nickLabel) {
        _nickLabel = [UILabel new];
        _nickLabel.textColor = [UIColor whiteColor];
        _nickLabel.font = [UIFont systemFontOfSize:12];
        _nickLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _nickLabel;
}

- (UILabel *)ageTagLabel {
    if(!_ageTagLabel) {
        _ageTagLabel = [UILabel new];
        _ageTagLabel.textColor = [UIColor whiteColor];
        _ageTagLabel.font = [UIFont systemFontOfSize:12];
        _ageTagLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _ageTagLabel;
}

- (UILabel *)sexLabel {
    if(!_sexLabel) {
        _sexLabel = [UILabel new];
        _sexLabel.textColor = [UIColor whiteColor];
        _sexLabel.font = [UIFont systemFontOfSize:12];
        _sexLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _sexLabel;
}

- (UIButton *)chatBtn {
    if(!_chatBtn) {
        _chatBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _chatBtn.backgroundColor = [UIColor yellowColor];
    }
    return _chatBtn;
}

- (UIButton *)likeBtn {
    if(!_likeBtn) {
        _likeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _likeBtn.backgroundColor = [UIColor redColor];
        [_likeBtn setTitle:@"喜欢" forState:UIControlStateNormal];
        [_likeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }
    return _likeBtn;
}

@end
